home *** CD-ROM | disk | FTP | other *** search
- unit Rweditu;
-
- interface
-
- uses
- StdCtrls;
-
- procedure AssignRWEdit(var F: TextFile; E: TEdit);
-
- implementation
-
- uses
- Forms, SysUtils;
-
- const
- {$ifdef Win32}
- FillerMax = 32;
- {$else}
- FillerMax = 16;
- {$endif}
-
- type
- TUserData = packed record
- Edit: TEdit;
- Filler: array[SizeOf(TEdit)+1..FillerMax] of Byte;
- end;
- {TUserData = packed record
- case Byte of
- 1: (
- Edit: TEdit);
- 2: (
- Filler: array[1..FillerMax] of Byte);
- end;}
-
- function RWEditOpen(var F: TTextRec): Integer; far; forward;
- function RWEditInput(var F: TTextRec): Integer; far; forward;
- function RWEditOutput(var F: TTextRec): Integer; far; forward;
- function RWEditClose(var F: TTextRec): Integer; far; forward;
-
- procedure AssignRWEdit(var F: TextFile; E: TEdit);
- begin
- { Set up text file variable }
- with TTextRec(F) do
- begin
- Handle := $FFFF;
- OpenFunc := @RWEditOpen;
- Mode := fmClosed;
- BufSize := SizeOf(Buffer);
- BufPtr := @Buffer;
- Name[0] := #0;
- { Set up edit control - store it in the text file variable }
- TUserData(UserData).Edit := E;
- end;
- end;
-
- function RWEditOpen(var F: TTextRec): Integer;
- begin
- Result := 0;
- with F do
- begin
- if Mode = fmInput then
- begin
- InOutFunc := @RWEditInput;
- FlushFunc := nil;
- end
- else
- begin
- Mode := fmOutput;
- InOutFunc := @RWEditOutput;
- FlushFunc := @RWEditOutput;
- end;
- CloseFunc := @RWEditClose;
- end;
- end;
-
- function RWEditInput(var F: TTextRec): Integer;
- begin
- Result := 0;
- with F, TUserData(UserData).Edit do
- begin
- BufPos := 0;
- BufEnd := GetTextBuf(PChar(BufPtr), BufSize);
- { Pop a carriage return line feed combo in }
- StrCat(PChar(BufPtr), #13#10);
- Inc(BufEnd, 2);
- { Clear the edit }
- Text := '';
- end;
- end;
-
- function RWEditOutput(var F: TTextRec): Integer;
- var
- { Temporary PChar holder }
- Buf: packed array[0..255] of Char;
- begin
- Result := 0;
- { This gets called when a Delphi 2 app shuts, in closing Output }
- { Since it refers to the edit which won't exist, don't run it }
- if not Application.Terminated then
- with F, TUserData(UserData).Edit do
- if BufPos <> 0 then
- begin
- { Get PChar with BufPos characters in }
- StrLCopy(Buf, PChar(BufPtr), BufPos);
- { Put that in the edit }
- SetTextBuf(Buf);
- { Reset BufPos }
- BufPos := 0;
- end;
- end;
-
- function RWEditClose(var F: TTextRec): Integer;
- begin
- Result := 0;
- end;
-
- end.
-